#include "../base.h"
#include "../include/AbsLayout.h"
#include <stdio.h>

#define LOG_TAG "AbsLayout"

extern jobject getActivity();

static jclass getClass(JNIEnv* env,const char * className)
{
	return (*env)->FindClass(env,className);
}

static jclass getAbsLayoutClass(JNIEnv* env)
{
	return getClass(env,"android/widget/AbsoluteLayout");
}

//创建一个绝对布局
AbsLayout newAbsLayout()
{
	JNIEnv* env = Android_JNI_GetEnv();
	jclass clazz = getAbsLayoutClass(env);
	static jmethodID methoID = NULL;
	if(methoID==NULL)
		methoID = (*env)->GetMethodID( env,clazz,"<init>","(Landroid/content/Context;)V" );
	jobject obj = (*env)->NewObject(env,clazz,methoID,getActivity());
	AbsLayout view = (*env)->NewGlobalRef(env,obj);
	(*env)->DeleteLocalRef(env,obj);
	(*env)->DeleteLocalRef(env,clazz);
	return view;
}

//删除一个绝对布局
void deleteAbsLayout(AbsLayout thiz)
{
	if(thiz==NULL)
	{
		LOGE("deleteAbsLayout thiz==NULL");
		return ;
	}
	JNIEnv* env = Android_JNI_GetEnv();
	(*env)->DeleteGlobalRef(env,thiz);
}


